package com.hcb.tonguetiphealth.widget.healthShare;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hcb.tonguetiphealth.adapter.GeneralPageAdapter;
import com.hcb.tonguetiphealth.global.Global;
import com.hcb.tonguetiphealth.manager.JSONManager;
import com.hcb.tonguetiphealth.model.Drinks;
import com.hcb.tonguetiphealth.model.HotResPackage;
import com.hcb.tonguetiphealth.model.Restaurant;
import com.hcb.tonguetiphealth.util.HttpUtils;
import com.hcb.tonguetiphealth.view.LoginActivity;
import com.hcb.tonguetiphealth.view.MoreActivity;
import com.hcb.tonguetiphealth.view.R;
import com.hcb.tonguetiphealth.view.ResBookActivity;
import com.hcb.tonguetiphealth.view.SearchActivity;
import com.hcb.tonguetiphealth.widget.GeneralWidget;
import com.hcb.tonguetiphealth.widget.home.HomeWidget;

public class HealthShareResearchWidget extends GeneralWidget implements OnClickListener {
	
	private Activity ctx;
	private Handler mHandler;
	private Button btSearch, btBack;
	private LinearLayout llBack;
	private EditText etSearch;
	private LayoutInflater inflater;
	private TextView tv1, tv2, tv3, tv4;
	
	
	private final static int SUCCESS = 0;
	
	public HealthShareResearchWidget(Context context) {
		super(context);
		ctx = (Activity)context;
		inflate(context, R.layout.healthshare_search_widget, this); 
		
		inflater = ctx.getLayoutInflater();
		etSearch = (EditText)findViewById(R.id.et_quick_search);
		btSearch = (Button)findViewById(R.id.bt_quick_search);
		llBack = (LinearLayout)findViewById(R.id.search_linearlayout_back);
		tv1 = (TextView)findViewById(R.id.tv_keyword1);
		tv2 = (TextView)findViewById(R.id.tv_keyword2);
		tv3 = (TextView)findViewById(R.id.tv_keyword3);
		tv4 = (TextView)findViewById(R.id.tv_keyword4);
		
		btSearch.setOnClickListener(this);
		llBack.setOnClickListener(this);
		setOnclick(tv1);
		setOnclick(tv2);
		setOnclick(tv3);
		setOnclick(tv4);
		
		
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch(msg.what) {
					case SUCCESS:
						break;
					}
				}
			};
			
	}
	
	private void setOnclick(final TextView tv){
		tv.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String keyword = tv.getText().toString();
				ctx.getIntent().putExtra("keyword", keyword);
				ctx.setContentView(new HealthShareWidget(ctx));
			}
		});
	}
	
	public void onClick(View v) {
		Intent intent = new Intent();
		switch(v.getId()) {
		case R.id.bt_quick_search:
			String keyword = etSearch.getText().toString();
			if(keyword !=null && !keyword.equals("") ){
				ctx.getIntent().putExtra("keyword", keyword);
				ctx.setContentView(new HealthShareWidget(ctx));
			}else {
				Toast.makeText(ctx, "搜索关键字不能为空", Toast.LENGTH_LONG).show();
			}
			break;
		case R.id.search_linearlayout_back:
			ctx.finish();
			break;
		default:
			break;
		}
		 
	}
 
	
	@Override
	public void notifyAdapter() {
		
	}
}
